﻿Imports System.Drawing.Drawing2D

Public Class PTIC_PanelGpeBox

    Private _borderColor As Color
    Private _labeltxt As String

    Public Sub New()

        InitializeComponent()

        'Activation de la transparence
        SetStyle(ControlStyles.SupportsTransparentBackColor, True)

        'Activation du double buffering
        SetStyle(ControlStyles.UserPaint, True)
        SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        SetStyle(ControlStyles.ResizeRedraw, True)

        BorderColor = Color.Black
        labelTxt = Me.Name

    End Sub

    Public Property BorderColor() As Color
        Get
            Return Me._borderColor
        End Get
        Set(ByVal value As Color)
            Me._borderColor = value
        End Set
    End Property

    Public Property labelTxt() As String
        Get
            Return _labeltxt
        End Get
        Set(ByVal value As String)
            _labeltxt = value
        End Set
    End Property

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        MyBase.OnPaint(e)

        Dim g As Graphics = e.Graphics
        Dim path As New GraphicsPath

        Dim tsize As Size = TextRenderer.MeasureText(Me._labeltxt, Me.Font)
        ''Dim tsizeBis As Size = g.MeasureString(Me._labeltxt, Me.Font, 10000)
        Dim txtWidth As Integer = tsize.Width + 15
        Dim txtHeight As Integer = tsize.Height
        Dim Xdecalage As Integer = 12
        Dim YDecalage As Integer = tsize.Height / 2

        'Gestion des bordures de thème
        Dim lpen As New Pen(My.Settings.OMANEBtnSTD_ColorDegrade, 1)

        Dim roundRect As Integer = My.Settings.OMANE_AngleRoundRect

        If roundRect > 0 Then
            g.SmoothingMode = SmoothingMode.AntiAlias

            'Haut Gauche
            path.AddArc(0, YDecalage, roundRect, roundRect, 180, 90)
            ''''g.DrawArc(lpen, 0, YDecalage, roundRect, roundRect, 180, 90)
            ''''g.DrawLine(lpen, 0, YDecalage + CType(roundRect / 2, Integer) + 1, 0, Me.Bounds.Height - 1 - CType(roundRect / 2, Integer))

            'Haut droite
            path.AddArc(Me.Bounds.Width - 1 - roundRect, YDecalage, roundRect, roundRect, 270, 90)
            ''''g.DrawArc(lpen, Me.Bounds.Width - 1 - roundRect, YDecalage, roundRect, roundRect, 270, 90)

            'Bas droite
            path.AddArc(Me.Bounds.Width - 1 - roundRect, _
                        Me.Bounds.Height - 1 - roundRect, _
                        roundRect, roundRect, 0, 90)
            ''''g.DrawArc(lpen, Me.Bounds.Width - 1 - roundRect, _
            ''''                Me.Bounds.Height - 1 - roundRect, _
            ''''                roundRect, roundRect, 0, 90)


            'Bas gauche
            path.AddArc(0, _
                        Me.Bounds.Height - 1 - roundRect, _
                        roundRect, roundRect, 90, 90)
        Else
            'TopLeft
            path.AddLine(0, YDecalage, 1, YDecalage)
            'TopRight
            path.AddLine(Me.Bounds.Width - 1, YDecalage, Me.Bounds.Width - 1, YDecalage + 1)
            'BottomRight
            path.AddLine(Me.Bounds.Width - 1, Me.Bounds.Height - 2, Me.Bounds.Width - 1, Me.Bounds.Height - 1)
            'BottomLeft
            path.AddLine(0, Me.Bounds.Height - 1, 0, Me.Bounds.Height - 2)
        End If
        
        ''''g.DrawArc(lpen, 0, _
        ''''               Me.Bounds.Height - 1 - roundRect, _
        ''''              roundRect, roundRect, 90, 90)

        path.CloseFigure()
        'Haut
        ''''g.DrawLine(lpen, CType(roundRect / 2, Integer) + 1, YDecalage, Xdecalage + CType(roundRect / 2, Integer) + 1, YDecalage)
        ''''g.DrawLine(lpen, Xdecalage + txtWidth, YDecalage, Me.Bounds.Width - 1, YDecalage)
        'Droite
        ''''g.DrawLine(lpen, Me.Bounds.Width - 1, YDecalage, Me.Bounds.Width - 1, Me.Bounds.Height - 1)
        'Bas
        ''''g.DrawLine(lpen, 0, Me.Bounds.Height - 1, Me.Bounds.Width - 1, Me.Bounds.Height - 1)

        ''''path.Equals

        g.DrawPath(lpen, path)
        g.DrawLine(New Pen(Color.White), Xdecalage, YDecalage, txtWidth, YDecalage)

        lpen.Dispose()

        'Ecriture du texte
        Dim lbrush As New SolidBrush(My.Settings.OMANE_ColorBorder)
        g.DrawString(Me._labeltxt, Me.Font, lbrush, New Rectangle(Xdecalage, 0, txtWidth, txtHeight))
        lbrush.Dispose()

    End Sub


End Class


''        Try
''            path = New GraphicsPath()
'Top right
''            If angleTopLeft = 0 Then
''                path.AddLine(zone.X, zone.Y, zone.X + 1, zone.Y)
''            Else
''                path.AddArc(zone.X, zone.Y, angleTopLeft, angleTopLeft, 180, 90)
''           End If

'Top left
''            If angleTopRight = 0 Then
''                path.AddLine(zone.X + zone.Width, zone.Y, zone.X + zone.Width, zone.Y + 1)
''            Else
''                path.AddArc(zone.X + zone.Width - angleTopRight, zone.Y, angleTopRight, angleTopRight, 270, 90)
''            End If

'Bottom right
''            If angleBottomRight = 0 Then
''                path.AddLine(zone.X + zone.Width, zone.Y + zone.Height, zone.X + zone.Width, zone.Y + zone.Height - 1)
''            Else
''                path.AddArc(zone.X + zone.Width - angleBottomRight, zone.Y + zone.Height - angleBottomRight, angleBottomRight, angleBottomRight, 0, 90)
''            End If

'Bottom left
''            If angleBottomRight = 0 Then
''                path.AddLine(zone.X, zone.Y + zone.Height, zone.X, zone.Y + zone.Height - 1)
''            Else
''                path.AddArc(zone.X, zone.Y + zone.Height - angleBottomLeft, angleBottomLeft, angleBottomLeft, 90, 90)
''            End If

''            path.CloseFigure()
''            Return path
''        Catch
''            Return Nothing
''        Finally
''            path = Nothing
''        End Try